//
//  MyJourneyTableViewCell.m
//  TravelFollowYourHeart
//
//  Created by appleLJ on 2017/12/13.
//  Copyright © 2017年 Lwx. All rights reserved.
//

#import "MyJourneyTableViewCell.h"

@interface MyJourneyTableViewCell ()

@property(nonatomic,strong) UILabel *titleLabel;
@property(nonatomic,strong) UIImageView *editImgView;
@property(nonatomic,strong) UIView *lineView;
@property(nonatomic,assign) int trip_id;

@end

@implementation MyJourneyTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.separatorInset = UIEdgeInsetsZero;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        //添加控件
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.editImgView];
        [self.contentView addSubview:self.lineView];
        
        //约束
        __weak __typeof(self)weakSelf = self;
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf).offset(10 / WIDTH_5S_SCALE);
            make.centerY.equalTo(weakSelf);
        }];
        [self.editImgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(weakSelf).offset(-10 / WIDTH_5S_SCALE);
            make.width.height.mas_equalTo(20 / WIDTH_5S_SCALE);
            make.centerY.equalTo(weakSelf);
        }];
        [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.bottom.right.equalTo(weakSelf);
            make.height.mas_equalTo(0.5);
        }];
    }
    return self;
}

#pragma mark -- event

//编辑
- (void)eidtTapGesture{
    NSLog(@"编辑");
    if (self.editHandle) {
        self.editHandle();
    }
}

//隐藏
- (void)hidden{
    self.editImgView.hidden = YES;
}
//显示
- (void)show{
    self.editImgView.hidden = NO;
}

#pragma mark -- init

- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = DEF_FontSize_14;
        _titleLabel.textColor = getColor(blackColor);
        _titleLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _titleLabel;
}

- (UIImageView *)editImgView{
    if (!_editImgView) {
        _editImgView = [[UIImageView alloc] init];
        _editImgView.image = [UIImage imageNamed:@"xc_edict"];
        _editImgView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(eidtTapGesture)];
        [_editImgView addGestureRecognizer:tap];
    }
    return _editImgView;
}

- (UIView *)lineView{
    if (!_lineView) {
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = getColor(dividerColor);
    }
    return _lineView;
}

//setter

- (void)setModel:(NSDictionary *)model{
    _model = model;
    self.titleLabel.text = model[@"name"];
}

- (void)setModelData:(MyJourneyModelData *)modelData{
    _modelData = modelData;
    self.titleLabel.text = [NSString stringWithFormat:@"%@", modelData.name];
    self.trip_id = [modelData.userId intValue];
}

@end
